﻿using System;
using System.Runtime.Serialization;

namespace YJKRevitBase.Algorithm.Octree.Data
{
	[DataContract]
	public struct Ray
	{
		[DataMember]
		public Point Origin;// { get; set; }

		public Point Direction
		{
			get
			{
				return this._direction;
			}
			set
			{
				this._direction = value.Normalized;
			}
		}

		public Ray(Point origin, Point direction)
		{
            this.Origin = origin;
            this._direction = direction.Normalized;
		}

		public Point GetPoint(float distance)
		{
			return this.Origin + this.Direction * distance;
		}

		public override string ToString()
		{
			return string.Format("Origin: {0}, Dir: {1}", this.Origin, this.Direction);
		}

		public string ToString(string format)
		{
			return string.Format("Origin: {0}, Dir: {1}", this.Origin.ToString(format), this.Direction.ToString(format));
		}

		[DataMember]
		private Point _direction;
	}
}
